// pages/search/search.js
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    values: "",

    // allArr:[{
    //   disease: [
    //     { con: "头疼" },
    //     { con: "头晕" },
    //     { con: "偏头痛" }
    //   ],
    //   disease1: [
    //     { con: "咳嗽性头疼" },
    //     { con: "慢性每日头疼" }
    //   ],
    // }],
    allArr: [],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var bgc = wx.getStorageSync('color')
    var id = ''
    wx.setNavigationBarColor({
      frontColor: "#ffffff",
      backgroundColor: bgc,
    })
    var that = this
    app.util.request({
      'url': "entry/wxapp/Questionimgsingle",
      data: {
        id: id
      },
      success: function(res) {
        console.log(res)
        var newarr = res.data.data;
        that.setData({
          qusetiontype: newarr,
        })
      },
      fail: function(err) {
        console.log(err)
      },
    })
  },
  inputClick: function(e) {

    var that = this
    var values = e.detail.value
    var alltjs = that.data.qusetiontype
    console.log(alltjs)
    var allArr = []
    for (var i = 0, len = alltjs.length; i < len; i++) {
      if (that.find(values, alltjs[i].question)) {
        allArr.push(alltjs[i])
      }
    }
    // console.log(allArr,alltjs)
    that.setData({
      values: values,
      allArr: allArr
    })
  },
  //模糊查找
  find: function(str, str1) {
    // for(var i = 0 , len = arr.length; i < len ; i++){
    if (str1.indexOf(str) !== -1) {
      return true
    }
    console.log(str)
    // }
    return false
  },
  delClick: function() {
    var values = ""
    console.log(values)
    this.setData({
      values: values
    })
  },
  //专家聊天
  zhuanLiaoClick: function(e) {
    console.log(e)
    var money = e.currentTarget.dataset.money
    var zid = e.currentTarget.dataset.zid
    var qid = e.currentTarget.dataset.qid
    var user_openid = e.currentTarget.dataset.openid
    var openid = wx.getStorageSync('openid')
    var fromuser = e.currentTarget.dataset.fromuser
    if (money == 0.00 || money == null) {
      wx.navigateTo({
        url: '/hyb_yl/userLife/pages/zhuan_liao/zhuan_liao?zid=' + zid + '&user_openid=' + user_openid + '&qid=' + qid + '&fromuser=' + fromuser,
      })
    } else {
      app.util.request({
        'url': 'entry/wxapp/Pay',
        header: {
          "Content-Type": "application/xml"
        },
        method: "GET",
        data: {
          openid: openid,
          z_tw_money: money
        },
        success: function(res) {
          console.log(res);
          wx.requestPayment({
            'timeStamp': res.data.timeStamp,
            'nonceStr': res.data.nonceStr, //字符串随机数
            'package': res.data.package,
            'signType': res.data.signType,
            'paySign': res.data.paySign,
            success: function(res) {
              wx.navigateTo({
                url: '/hyb_yl/userLife/pages/zhuan_liao/zhuan_liao?zid=' + zid + '&user_openid=' + user_openid,
              })
              app.util.request({
                'url': "entry/wxapp/Goodsinfo",
                data: {
                  money: money,
                  qid: qid,
                  openid: openid,
                  type1: 1
                },
                header: {
                  'content-type': 'application/json'
                },
                success: function(res) {
                  console.log(res)
                },
                fail: function(err) {
                  console.log(err)
                },
              })
            },
            fail: function(err) {
              app.util.request({
                'url': "entry/wxapp/Goodsinfo",
                data: {
                  money: money,
                  qid: qid,
                  openid: openid,
                  type1: 0
                },
                header: {
                  'content-type': 'application/json'
                },
                success: function(res) {
                  console.log(res)
                },
                fail: function(err) {
                  console.log(err)
                },
              })
            }
          })
        },
        fail: function(err) {
          console.log(err);
        }
      })
    }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})